package com.mc.cloud.mall.common.common;

import com.google.common.collect.Sets;
import com.mc.cloud.mall.common.exception.MallException;
import com.mc.cloud.mall.common.exception.MallExceptionEnum;
import org.springframework.stereotype.Component;

import java.util.Set;

/**
 * @ClassName Constants
 * @Author MC
 * @Date 2021/5/20 12:50
 * @Version 1.0
 **/
@Component
public class Constant {
    
    public static final String SALT  = "dihwaug89'[5.dwa";
    public static final String MALL_USER  = "mall_user";
    
    public interface ProductListOrderBy{
        Set<String> PRICE_ASC_DESC = Sets.newHashSet("price desc","price asc");
    }
    
    public interface SellStatus{
        int NOT_SALE = 0 ;//商品下架状态
        int SALE = 1 ;//商品上架状态
    }
    
    public interface Cart{
        int UN_CHECKED = 0 ;//购物车未选中状态
        int CHECKED = 1 ;//购物车选中状态
    }
    
    public enum OrderStatusEnum {
        CANCELED(0,"用户已取消"),
        NOT_PAID(10,"未付款"),
        PAID(20,"已付款"),
        DELIVERED(30,"已发货"),
        FINISHED(40,"交易完成");
        
        private Integer code;
        private String value;
        
        OrderStatusEnum(Integer code, String value) {
            this.code = code;
            this.value = value;
        }
        
        public static OrderStatusEnum codeOf(Integer code){
            for (OrderStatusEnum orderStatusEnum :values()){
                if (orderStatusEnum.getCode().equals(code)){
                    return orderStatusEnum;
                }
            }
            throw new MallException(MallExceptionEnum.NO_ENUM);
        }
        public Integer getCode() {
            return code;
        }
        
        public void setCode(Integer code) {
            this.code = code;
        }
        
        public String getValue() {
            return value;
        }
        
        public void setValue(String value) {
            this.value = value;
        }
    }
    
}
